package com.bignerdranch.android.technew;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import java.util.List;

/**
 * Created by Administrator on 2016/7/15.
 */
public class ListViewAdapter extends BaseAdapter {

    private List<Bean> mBeanList;
    private LayoutInflater mInflater;
    private Context mContext;

    public ListViewAdapter(Context context,List<Bean> beanList) {
        mBeanList = beanList;
        mInflater = LayoutInflater.from(context);
    }

    @Override
    public int getCount() {
        return mBeanList.size();
    }

    @Override
    public Object getItem(int position) {
        return mBeanList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView==null){
            convertView = mInflater.inflate(R.layout.item,null);
        }
        ViewHandler handler = new ViewHandler();
        if (convertView.getTag() == null){
            handler.name = (TextView) convertView.findViewById(R.id.text);
            convertView.setTag(handler);
        }else {
            handler = (ViewHandler) convertView.getTag();
        }

        handler.name.setText(mBeanList.get(position).getItem());


        return convertView;
    }
    private static class ViewHandler{

        public TextView name;

    }
}
